import sys
from loguru import logger
from settings import settings


# Convenient function to avoid repetition, but you could simply go with a lambda
def _make_filter(name):
    def filter(record):
        return record["extra"].get("name") == name

    return filter


class EmptyLogger:
    def info(self, text: str, var=None):
        pass

    def debug(self, text: str, var=None):
        pass


logger.add(
    "./logs/debug.log",
    format="{time:MMMM D, YYYY > HH:mm:ss} | {level} | {message}",
    level="DEBUG",
    rotation="1 hour",
    filter=_make_filter("debug"),
)

debugger = logger.bind(name="debug") if not settings.is_prod else EmptyLogger()


logger.add(
    "./logs/logs.log",
    format="{time:MMMM D, YYYY > HH:mm:ss} | {level} | {message}",
    rotation="1 week",
    compression="zip",
    level="WARNING",
    filter=_make_filter("errors"),
)

log = logger.bind(name="errors")
